home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / interapplication comm / 7edit / source / svaeobjectsexist.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  2.7 KB  |  98 lines

  1. /*
  2.     File:        SVAEObjectsExist.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by: Original version by Jon Lansdell and Nigel Humphreys.
  7.                 3.1 updates by Greg Sutton.
  8.  
  9.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  10.  
  11.                 You may incorporate this Apple sample source code into your program(s) without
  12.                 restriction. This Apple sample source code has been provided "AS IS" and the
  13.                 responsibility for its operation is yours. You are not permitted to redistribute
  14.                 this Apple sample source code as "Apple sample source code" after having made
  15.                 changes. If you're going to re-distribute the source, we require that you make
  16.                 it clear in the source that the code was descended from Apple sample source
  17.                 code, but that you've made changes.
  18.  
  19.     Change History (most recent first):
  20.                 7/20/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  21.                 
  22.  
  23. */
  24.  
  25. #include "SVAEObjectsExist.h"
  26.  
  27. #include "SVEditAEUtils.h"
  28.  
  29.  
  30. #pragma segment AppleEvent
  31.  
  32.  
  33. // -----------------------------------------------------------------------
  34. //    Name:         DoObjectsExist
  35. //    Purpose:    Handles the kAEDoObjectsExist AppleEvent. Basically just
  36. //                tries to resolve the object to see if it exists.
  37. // -----------------------------------------------------------------------
  38.  
  39. pascal OSErr DoObjectsExist(const AppleEvent    *theAppleEvent,
  40.                                     AppleEvent    *reply, 
  41.                                     long        handlerRefCon)
  42. {
  43. #pragma unused (handlerRefCon)
  44.  
  45.     AEDesc            directObject = {typeNull, NULL},
  46.                     directDesc = {typeNull, NULL},
  47.                     replyDesc = {typeNull, NULL};
  48.     long            itemCount;
  49.     Boolean           exists;
  50.     OSErr             existsErr,
  51.                     err;
  52.             
  53.     err = AEGetParamDesc(theAppleEvent, keyDirectObject, typeWildCard, &directObject);
  54.  
  55.     err = GotRequiredParams(theAppleEvent);
  56.     if (noErr != err) goto done;
  57.  
  58.     if (typeNull == directObject.descriptorType)
  59.         exists = true;        // Yes, our application does exist?????
  60.     else
  61.     {
  62.         existsErr = AEResolve(&directObject, kAEIDoMinimum, &directDesc);
  63.         
  64.         if (noErr == existsErr)
  65.         {
  66.             if (typeAEList == directDesc.descriptorType)    // If it's a list then objects
  67.             {                                                // exist only if the list
  68.                 err = AECountItems(&directDesc, &itemCount);// is not empty.
  69.                 if (noErr != err) goto done;
  70.  
  71.                 if (itemCount)
  72.                     exists = true;
  73.                 else
  74.                     exists = false;
  75.             }
  76.             else
  77.                 exists = true;                                // Otherwise it resolved
  78.         }                                                    // so it exists.
  79.         else
  80.             exists = false;
  81.     }
  82.     
  83.     err = AECreateDesc(typeBoolean, (Ptr)&exists, sizeof(exists), &replyDesc);
  84.     if (noErr != err) goto done;
  85.     
  86.     err = AddResultToReply(&replyDesc, reply, err);
  87.     
  88. done:
  89.     if (directObject.dataHandle)
  90.         AEDisposeDesc(&directObject);
  91.     if (directDesc.dataHandle)
  92.         AEDisposeDesc(&directDesc);
  93.     if (replyDesc.dataHandle)
  94.         AEDisposeDesc(&replyDesc);
  95.         
  96.     return(err);
  97. } // DoObjectsExist
  98.